These samples demonstrate how to use various query operators on XML data, such as TakeWhile, Any, All, Distinct, Concat, and others.

[Category("Query")]
[Description("List books until total price is less that $150")]
public void XLinq39()
{
XDocument doc = XDocument.Load("bib.xml");
double sum = 0;
var query = doc.Descendants("book")
.TakeWhile(c => (sum += (double)c.Element("price")) <= 150);
foreach (var result in query)
Console.WriteLine(result);
}
[Category("Query")] [Description("List books until total price is less that $150")] public void XLinq39() { XDocument doc = XDocument.Load("bib.xml"); double sum = 0; var query = doc.Descendants("book") .TakeWhile(c => (sum += (double)c.Element("price")) <= 150); foreach (var result in query) Console.WriteLine(result); }
For more information on LINQ to XML: http://msdn.microsoft.com/en-us/library/bb387098.aspx